/**
 * 判断tomcat存不存
 * 不存在时部署tomcat
 * @param ip
 * @param tomcatPath  tomcat本地文件
 * @param tomcatFileName  tomcat压缩包的名字
 * @param remotePath  远程目录
 * @param tomcatName  部署后的文件名
 */
void call(String ip, String tomcatPath, String tomcatFileName, String remotePath, String tomcatName) {
    print("开始检查文件${tomcatName}是否存在")
    withCredentials([sshUserPrivateKey(
            credentialsId: 'ssh_key',  // 凭证 ID
            keyFileVariable: 'SSH_KEY',
            usernameVariable: 'USER'
    )]) {
        // 检查远程服务器上目录是否存在
        def dirExists = ssh.sshReturn(ip," test -d ${remotePath}${tomcatName} && echo 'exists' || echo 'not exists' ")
        print("dirExists:"+dirExists)
        //       目录不存在时部署tomcat
        if (dirExists.contains('not exists')) {
        print("${tomcatName}不存在,开始部署")
        scp.call(ip, tomcatPath, remotePath, tomcatFileName)
        ssh.sshReturn(ip, " tar -zxvf ${remotePath}${tomcatFileName}  -C ${remotePath}")
        }else{
        print("${tomcatName}已存在")
        }
    }
}
